package com.att.action;

import com.adkfp.utils.LayuiUtil;
import com.att.bean.ParamBean;
import com.att.service.ParamService;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;

import javax.annotation.Resource;
import java.util.List;

@Controller
@RequestMapping("param")
public class ParamAction {

    @Resource(name = "paramService")
    private ParamService paramService;

    /**
     * Description: 带条件查询考勤规则记录
     *
     * @param bean
     */
    @RequestMapping("selectAll")
    @ResponseBody
    public Object selectAll(ParamBean bean) {
        List<ParamBean> list = paramService.findByCondition(bean);
        return LayuiUtil.data(Long.valueOf(list.size()), list);
    }

    /**
     * Description: 转发到页面
     */
    @RequestMapping("paramIndex")
    public String paramIndex() {
        return "settings/attendanceRule";
    }

    //修改
    @RequestMapping("update")
    @ResponseBody
    public String update(ParamBean bean) {
        List<ParamBean> list = paramService.findByCondition(bean);
        if (list.size() > 0) {
            boolean flag = paramService.update(bean);
            if (flag) {
                return "SUCCESS";
            }
        }else {
            boolean flag = paramService.insert(bean);
            if (flag) {
                return "SUCCESS";
            }
        }
        return "ERROR";
    }
}
